/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kindatamanip;

import java.util.ArrayList;

/**
 *
 * @author thbrandston
 */
public class DipOrg {

    public int[][] loci;
    public DipOrg parent1;
    public DipOrg parent2;
    public ArrayList<DipOrg> children;
    
    // this may be used to allow easier calculation or manipulation of genes/groups of genes
    public int variation;

    public DipOrg(int nloci, int vari)
    {
        loci = new int[nloci][2];
        parent1 = null;
        parent2 = null;
        children = null;
        variation = vari;
    }

//    public void fillLoci()
//    {
//        if(loci == null)
//            return;
//
//        for(int i = 0; i < loci.length; i++)
//        {
//            loci[i][0] = (int)Math.floor(Math.random()*256);
//            loci[i][1] = (int)Math.floor(Math.random()*256);
//        }
//    }

    public void addChild(DipOrg c)
    {
        if(children == null)
            children = new ArrayList<DipOrg>(0);

        children.add(c);
    }

    public void setLocus(int locus, int allele1, int allele2)
    {
        if(loci == null)
            return;

        loci[locus][0] = allele1;
        loci[locus][1] = allele2;
    }

    public void setParents(DipOrg p1, DipOrg p2)
    {
        parent1 = p1;
        parent2 = p2;
    }

    public boolean hasParent(DipOrg par)
    {
       if(par == parent1 || par == parent2)
           return true;
       return false;
    }

    public int getEitherAlleleAt(int locus)
    {
        return loci[locus][(int)Math.floor(Math.random()*2)];
    }
  
}
